<br />
<?php
echo '<fieldset id="year" style="margin: 0 auto;width:91.5%;height: auto;border: 1px #ccc solid; padding:20px;-moz-border-radius:10px;">';

    echo '<div style="float:left; border: 0px #ccc solid; margin-right: 15px;">';
    echo anchor('report/manager', img('images/user_images/cancel.png'),array('title'=>'Back'));
    echo '</div>';
     
$dat_from = $this->input->post('txt_datestart');
$dat_to = $this->input->post('txt_date_to');
$this->db->select('sal_date,sal_quantity,use_username,car_name,sal_price,sal_payment');
$this->db->from('tbl_sale');
$this->db->join('tbl_card', 'tbl_card.car_id=tbl_sale.car_id');
$this->db->join('tbl_car_type', 'tbl_car_type.car_type_id=tbl_card.car_type_id');
$this->db->where('sal_date >=', $dat_from);
$this->db->where('sal_date <=', $dat_to);
$get_report_value = $this->db->get();

echo '<table width="100%" cellspacing="0" cellpadding="0" border="1">
              <tr>
                <th colspan="8" align="center" style="color:#5C9416;padding:5px;background-color:#FFF;font-size:20px;">Card sale</th>
              </tr>
              <tr style="background-color:#5C9416;text-align:center;color:#FFF;height:25px;">
                <th>N&ordm</th>
                <th>Sele Date</th>
                 <th>Seller</th>
                <th>Items</th>
                <th>Quantity</th>
                <th>Unit Price</th>
                <th>Payment</th>
                <th>Credit</th>
              </tr>';
$j = 1;

foreach ($get_report_value->result() as $report) { //======================loop data from database as a row ================
    echo '<tr style="text-align:center;color:#000;font-weight: lighter;padding:4px;">
                  <td style="text-align:center;">' . $j . '</td>
                  <td style="text-align:center;">' . $report->sal_date . '</td>
                  <td style="text-align:center;">' . $report->use_username . '</td>
                  <td style="text-align:center;">' . $report->car_name . '</td>
                  <td style="text-align:center;">' . $report->sal_quantity . '</td>
                  <td style="text-align:center;">$' . $report->sal_price . '</td>
                  <td style="text-align:center;">$' . $report->sal_payment . '</td>
                  <td style="text-align:center;">$' . ($report->sal_quantity * $report->sal_price - $report->sal_payment) . '</td>
                  </tr>';
    $j++;
}
echo '</table>';
/*$dat_from = $this->input->post('txt_datestart');
$dat_to = $this->input->post('txt_date_to');
$this->db->select('sal_date,sal_quantity,use_username,car_name,sal_price,sal_payment');
$this->db->from('tbl_sale');
$this->db->join('tbl_card', 'tbl_card.car_id=tbl_sale.car_id');
$this->db->join('tbl_car_type', 'tbl_car_type.car_type_id=tbl_card.car_type_id');
$dateRange = "sal_date BETWEEN '$dat_from%' AND 'txt_datestart%'";
$this->db->where($dateRange, NULL, FALSE);
$get_report_value = $this->db->get();*/

$dat_from = $this->input->post('txt_datestart');
$dat_to = $this->input->post('txt_date_to');
$get_report_value=$this->db->query("SELECT sum(sal_quantity * sal_price) AS total, SUM(sal_quantity * sal_price - sal_payment) AS credit
FROM tbl_sale
INNER JOIN tbl_card ON tbl_card.car_id = tbl_sale.car_id
JOIN tbl_car_type ON tbl_car_type.car_type_id = tbl_card.car_type_id WHERE sal_date between '$dat_from' and '$dat_to' ");
 if ($get_report_value->num_rows() > 0) {
                    echo '<table id="mytable" style="float:right;text-align:center; ">';
                    echo '<tr style=" color: #FFF; background-color:#5C9416;">';
                    echo ' <th  height="20px" width="100px" ><center>Total</center></th>';
                    echo '<th  height="20px" width="100px"><center>Credit</center></th>';
                    echo '</tr>';
                    echo '</tr>';
                    foreach ($get_report_value->result() as $value) {
                        echo '<td style="color:red;font-weight:Bold"><center>$' . $value->total . '</center></td>';
                        echo '<td style="color:red;font-weight:Bold;text-align:center;">$' . $value->credit . '</td>';
                    }
                    echo ' </tr>';
                }
                echo '</table>';
//===============================end report sale card=================/
echo '<br/>';
echo '</br/>';
echo '</br/>';

$dat_from = $this->input->post('txt_datestart');
$dat_to = $this->input->post('txt_date_to');
$this->db->select('*');
$this->db->from('tbl_sale');
$this->db->join('tbl_product', 'tbl_product.pro_id=tbl_sale.pro_id');
$this->db->where('sal_date >=', $dat_from);
$this->db->where('sal_date <=', $dat_to);
$get_product_value = $this->db->get();

echo '<table   width="100%" cellspacing="0" cellpadding="0" border="1">
              <tr>
                <th colspan="8" align="center" style="color:#008000;padding:5px;background-color:#FFF;font-size:20px;">Products</th>
              </tr>
              <tr style="background-color:#5C9416;text-align:center;color:#FFF;height:25px;">
                <th>N&ordm</th>
                 <th>Sell Date</th>
                 <th>Seller</th>
                <th>Items</th>
                <th>Quantity</th>
                <th>Unit Price</th>
                <th>Payment</th>
              </tr>';
$j = 1;
foreach ($get_product_value->result()as $reports) {
    //  echo $reports->pro_name.'<br/>';
    //  echo $reports->sal_quantity*$reports->sal_price.'</br>';
    // echo $report->car_name;


    echo '<tr style="text-align:center;color:#000;font-weight: lighter;">
                  <td>' . $j . '</td>
                  <td>' . $reports->sal_date . '</td>
                  <td >' . $reports->use_username . '</td>
                  <td>' . $reports->pro_name . '</td>
                  <td >' . $reports->sal_quantity . '</td>
                  <td>$' . $reports->sal_price . '</td>
                  <td>$' . $reports->sal_price * $reports->sal_quantity . '</th>
                  </tr>';
    $j++;
}
echo '</table>';

$dat_from = $this->input->post('txt_datestart');
$dat_to = $this->input->post('txt_date_to');
$data_product_total = $this->db->query("SELECT  sum(sal_quantity * sal_price ) AS totals
FROM tbl_sale
INNER JOIN tbl_product ON tbl_product.pro_id = tbl_sale.pro_id
JOIN tbl_pro_type ON tbl_pro_type.pro_type_id = tbl_product.pro_type_id
WHERE sal_date between '$dat_from' and '$dat_to'");
if ($data_product_total->num_rows() > 0) {
                    echo '<table border="1"style="float:right;text-align:center;" cellpadding="0" cellspacing="0" >';
                    echo '<tr style=" color: #FFF; background-color:#5C9416;">';
                    echo ' <th  height="20px" width="100px" ><center>Total</center></th>';
                   
                    echo '</tr>';
                    echo '</tr>';
                    foreach ($data_product_total->result() as $value) {
                        echo '<td style="color:red;font-weight:Bold;"><center>$' . $value->totals . '</center></td>';                     
                    }
                    echo ' </tr>';
                }
                echo '</table>';
                echo '</fieldset>';
?>
    